package com.example.orderserver.callback;

import com.example.orderserver.feign.ProductFeignNacos;
import com.example.productserverapi.entity.Product;
import com.netflix.client.ClientException;
import feign.FeignException;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author benjamin_5
 * @Description
 * @date 2023/3/9
 */
@Component
public class ProductFeignCallBackFactory implements FallbackFactory<ProductFeignNacos> {

    @Override
    public ProductFeignNacos create(Throwable cause) {
        return new ProductFeignNacos() {
            @Override
            public String getInfo() throws ClientException {
                if(cause instanceof FeignException.InternalServerError){
                    return "远程服务器挂掉咯";
                }else if(cause instanceof RuntimeException){
                    // 熔断
                    throw (RuntimeException) cause;
                }
                return "Cloud7DayProperties{'name':'兜底数据','price':0, 'size': 0}";
            }

            @Override
            public String getByName(String name) {
                return null;
            }

            @Override
            public String getByBody(Product product) {
                return null;
            }

            @Override
            public String getByBody2(Map product) {
                return null;
            }

            @Override
            public String getByBody3(Product product) {
                return null;
            }

            @Override
            public String getByBody4(Product product) {
                return null;
            }
        };
    }
}
